/**
 * 
 */
package com.asdf.tests;

import java.util.Random;

import com.asdf.external.DBUserDetails;

/**
 * @author ilia
 *
 */
public class SimpleUser
{
	public String	id;
	public String	firstName;
	public String	lastName;
	public String	email;
	public String	address;
	public boolean	isMember;
	public String	club;
	public boolean	getNewsletter;
	public String	username;
	public String	password;

	public SimpleUser() {
		this(RandomString.get(), RandomString.get());
	}
	
	public SimpleUser( String id, String username) {
		this(id, username, false, null);
	}
	
	public SimpleUser( String id, String username, String club) {
		this( id, username, true, club);
	}
	
	public SimpleUser( String id, String username,
			boolean isMember, String club)
	{
		this(id, username, isMember, club, 
				RandomString.get(), RandomString.get(),
				RandomString.get(), RandomString.get(),
				new Random().nextBoolean(), null); 
	}

	public SimpleUser( String id, String username,
			boolean isMember, String club,
			String firstName, String lastName,
			String email, String address, 
			boolean getNewsletter)
	{
		this(id, username, isMember, club, firstName, lastName,
				email, address, getNewsletter, null); 
	}

	public SimpleUser( String id, String username,
			boolean isMember, String club,
			String firstName, String lastName,
			String email, String address, 
			boolean getNewsletter, String password)
	{
		this.id = id;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.address = address;
		this.isMember = isMember;
		this.club = club;
		this.getNewsletter = getNewsletter;
		this.username = username;
		this.password = password;
	}

	private static boolean eq(String s1, String s2) {
		if (s1==null || s2==null)
			return s1==null && s2==null;
		return s1.equalsIgnoreCase(s2);
	}
	
	public boolean equals(DBUserDetails u) {
		return password.equals(u.getPassword()) && 
				eq(id,			u.getId()) 			&& eq(username, u.getUsername()) 			&&
				eq(firstName, 	u.getFirstName())	&& eq(lastName, u.getLastName()) 			&&
				eq(email, 		u.getEmail())		&& eq(address,	u.getAddress()) 			&&
				isMember==u.getAviationClubMember() && eq(club, 	u.getAviationCompanyName()) &&
				getNewsletter==u.getGetNewsLetters();
	}
	
	SimpleUser setNewsletter(boolean b) {
		getNewsletter = b;
		return this;
	}
}
